//位置计算距离
function	getDistance(la1, lo1, la2, lo2) {  // 当前的纬度，当前的经度，接口拿到的纬度，接口拿到的经度
	    let La1 = la1 * Math.PI / 180.0;
	    let La2 = la2 * Math.PI / 180.0;
	    let La3 = La1 - La2;
	    let Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
	    let distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2)));
		distance = distance * 6378.137;
	    distance = Math.round(distance * 10000) / 10000;
		//保留小数点后3位
		
	   if (distance > 1) {
		   distance =distance.toFixed(1)
	  		return distance+ 'km  ';
	  	} else {
			distance =distance.toFixed(3)
			distance = distance.toString();
			distance=distance.split('.')[1];
			distance=distance.replace(/\b(0+)/gi,"")
	  		return distance +"m";
	  	}
		
		///let s=la1*Math.PI/180.0
}
//时间格式化
function dateFormat(time) {
    let date = new Date(time);
    let year = date.getFullYear();
    // 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
    let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    // 拼接
   //  return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
    return year + "-" + month + "-" + day+ " " + hours + ":" + minutes ;
}
function developing(){
	uni.$u.toast("功能开发中！！！")
}
function notLogin(){
	uni.showModal({
	    title: '提示',
	    content: '账号未登录',
		showCancel: false,//没有取消按钮的弹框
		buttonText: '确定',
	    success: function (res) {
		uni.navigateTo({
				   url: "/pages/login/login"
				});
			}
	});
}
module.exports = {
     getDistance: getDistance,
	 dateFormat:dateFormat,
	 developing:developing,
	 notLogin:notLogin
 }